// pages/welcome/welcome.js
import CommonService from '../../service/CommonService.js';
import { throttle } from '../../utils/util.js';
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
  
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.commonService = new CommonService();
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    const _ = this;
    const param = { state: 1, type: 2 };
    this.commonService.listAd(param).then(function (result) {
      if (result.status == 0 && result.data.length > 0) {
        _.setData({ adInfo: result.data[0] });
      }
    })
  },
  lookOrder: function(){
    throttle(() => {
      wx.navigateTo({
        url: '/pages/home/home?type=order'
      })
    }, 1000)();
  },
  lookFactory: function(){
    throttle(() => {
      wx.navigateTo({
        url: '/pages/home/home?type=factory'
      })
    }, 1000)();
  },
  toRuZhu: function (e) {
    const { user } = app.globalData;
    if(user.authStatus == 1||user.authStatus == 3){
      wx.navigateTo({
        url: '/packageUser/pages/auth/auditting?authStatus=' + user.authStatus
      })
      return;
    }
    wx.showActionSheet({
      itemList: ['工厂方认证', '订单方认证'],
      success: function (res) {
        if (res.tapIndex == 0) {
          wx.navigateTo({
            url: '/packageUser/pages/auth/auth-rules'
          })
        } else {
          wx.navigateTo({
            url: '/packageUser/pages/auth/business-auth'
          })
        }

      },
      fail: function (res) {
        console.log(res.errMsg)
      }
    })
  }
})